<template>
	<BaseContainer
		class="report-table-wrapper"
		v-loading="loading"
		element-loading-text="加载中..."
		element-loading-background="rgba(255, 255, 255, 0.8)"
	>
		<div class="t-header">
			<div @click="drawer = !drawer" class="article-title">
				<p
					class="text-tip"
					id="no-print"
					v-if="modelData.viewStatus"
					:style="{ opacity: modelData['viewStatus'] == null ? 0 : 1, '--base-text-bg': modelData['viewStatus'] == 1 ? '' : '#dc8844af' }"
				>
					<span class="tip-text-detail" v-if="modelData.viewStatus == 1">详</span>
					<span class="tip-text-new" v-else>新</span>
				</p>
				<span>南京市居家适老化改造申请表</span>
			</div>
		</div>
		<ReportTable :column="dataList" :isDetail="true" :moreNewsModel="moreNewsModel" :baseModel="baseModel" :model="modelData" @change="handleSave">
			<template v-slot:slot1>
				<CheckSelect v-model="modelData.houseType" :isDetail="true" :dictData="houseType"></CheckSelect>
			</template>
			<template v-slot:slot2>
				<CheckSelect v-model="modelData.type" :isLine="true" :isDetail="true" :dictData="personType">
					<template v-slot:name0>
						<div style="margin-left: 20px">
							<CheckSelect v-model="modelData.detailType" :isDetail="true" :dictData="assistObjType"></CheckSelect>
						</div>
					</template>
				</CheckSelect>
				<div style="width: 100%; text-align: right">（在所选项前&#9744;内划“√”,并附相关证明材料）</div>
			</template>
			<template v-slot:slot3>
				<CheckSelect v-model="modelData.renovationProject" :isDetail="true" :dictData="rtrofitNeedsType"></CheckSelect>
			</template>
			<template v-slot:slot4>
				<div>本人及家庭成员自原在政府通过招投标确定的施工单位中选取一家单位进行居家适老化改造，同意政府补助的规定，愿意承担房屋改造中相关责任。</div>
				<div class="yi_jian">
					<div>申请人（亲属）签字</div>
					<div v-if="modelData.signature">
						<PreviewImg style="height: 75px; width: 75px" :src="modelData.signature" />
					</div>
					<div>&nbsp;&nbsp;&nbsp;年&nbsp;&nbsp;&nbsp;月&nbsp;&nbsp;&nbsp;日</div>
				</div>
			</template>
			<template v-slot:slot5>
				<div>经审核，该老年家庭属第____类家庭，适老化改造费用由财政补贴____%,补贴金额上限____元，超出部分自行承担。</div>
				<div class="yi_jian">
					<div>签字：</div>
					<div>单位（盖章）</div>
					<div>&nbsp;&nbsp;&nbsp;年&nbsp;&nbsp;&nbsp;月&nbsp;&nbsp;&nbsp;日</div>
				</div>
			</template>
			<template v-slot:slot6>
				<div class="yi_jian">
					<div>签字：</div>
					<div>单位（盖章）</div>
					<div>&nbsp;&nbsp;&nbsp;年&nbsp;&nbsp;&nbsp;月&nbsp;&nbsp;&nbsp;日</div>
				</div>
			</template>
		</ReportTable>
		<AplidDialog v-model="archivalShow" tilte="老人档案" whickComm="detail" :customeHeader="detailConfig?.customeHeader" :model="modelData">
			<ElderArchives :showBtn="false" :nowRowData="modelData" :noOperation="true"></ElderArchives>
		</AplidDialog>
	</BaseContainer>
</template>

<script setup lang="ts">
import ReportTable from './ReportTable/index.vue'
import Oldman from '../oldman/index.vue'
import apiMod from '@/apiMod'
import { filterEmptyObj } from '@/utils/util'
import PreviewImg from '@/views/aplid/DetailPage/ContentListItem/FileList/PreviewImg/index.vue'

import bus from '@/utils/eventbus'
import CheckSelect from './CheckSelect/show.vue'
import ElderArchives from '@/views/instOperate/components/ApplyReport/oldman/Archives/index.vue'

const props = defineProps<{
	params?: any
	creditCode?: string | number
	editData?: any
	isDetail?: boolean
	caseId?: string | number
	custome?: boolean
	approvalStatus?: string | number
	otherData?: any
	isPigeonhole?: boolean
}>()

const emit = defineEmits(['save'])

let archivalShow = ref(false)
const detailConfig = {
	customeHeader: {
		integrityConfig: {
			baseTableName: 'dp_service_object',
			materialTableName: 'dp_service_object_material',
			soleValue: 'idCard',
		},
		type: 'CardTwo',
		title: 'name',
		avatar: 'image',
		tipList: [{ prop: 'telephone', type: 'tip-success', label: '联系电话' }],
		tagList: [
			{
				prop: 'countryLevel',
				propName: 'countryLevelLabel',
				code: 'ACCESS_LEVEL_COUNTRY',
				custome: 'tag',
				type: 'success',
				label: '能力等级',
			},
			// { prop: 'birthday', type: 'success', label: '公历' },
			// { prop: 'lunarBirthday', type: 'success', label: '农历' },
		],
	},
}
const model = ref({
	year: '',
	month: '',
})
const drawer = ref(false)
const baseModel: any = shallowRef({})
const loading = ref(false)
const modelData: any = ref({})
const orgArchivesEl = ref(null)
let moreNewsModel: any = ref({})
let houseType = [
	{ label: '电梯房', value: '0' },
	{ label: '步梯房', value: '1' },
	{ label: '平房', value: '2' },
]
let rtrofitNeedsType = [
	{ label: '地面改造；', value: '0' },
	{ label: '门改造；', value: '1' },
	{ label: '卧室改造；', value: '2' },
	{ label: '如厕洗浴设备改造；', value: '3' },
	{ label: '厨房设备改造；', value: '4' },
	{ label: '物理环境改造', value: '5' },
	{ label: '老年用品配置', value: '6' },
]
let personType = [
	{ label: '第一类：政府养老扶助对象', value: '0' },
	{ label: '第二类：南京户籍年满80周岁老年人家庭', value: '1' },
	{ label: '第三类：南京户籍65-79周岁老年人家庭', value: '2' },
]
let assistObjType = [
	{ label: '1.特困老年人；', value: '0' },
	{ label: '2.最低生活保障家庭以及最低生活边缘家庭中的老年人；', value: '1' },
	{ label: '3.经济困难的失能、半失能老年人', value: '2' },
	{ label: '4.计划生育特殊家庭老人；', value: '3' },
	{ label: '5.百岁老人；', value: '4' },
]

let oldmanArchivesEl = ref()
const tableColumnConfig = (data?: any) => {
	return new Promise((resovle) => {
		const config = [
			[
				{ m: '老人姓名', style: { width: '180px' } },
				{
					m: '',
					style: { width: '180px' },
					prop: 'name',
					archives: true,
					archivesText: '档案',
					showLink: (col, model) => {
						archivalShow.value = true
					},
				},
				{ m: '性别' },
				{
					m: 'gender',
					setColor: true,
					style: { width: '180px' },
					prop: 'genderLabel',
				},
			],

			[
				{ m: '身份证号' },
				{
					m: '',
					prop: 'idCard',
					setColor: true,
				},
				{ m: '联系电话' },
				{
					m: '',
					prop: 'telephone',
					setColor: true,
				},
			],
			[
				{ m: '户籍地址' },
				{
					setColor: true,
					m: '',
					prop: 'crAddress',
					mc: {
						rs: 1,
						cs: 3,
					},
				},
			],
			[
				{ m: '家庭住址' },
				{
					setColor: true,
					m: '',
					prop: 'address',
					mc: {
						rs: 1,
						cs: 3,
					},
				},
			],
			[
				{
					m: '住宅情况',
					mc: {
						rs: 2,
						cs: 1,
					},
				},
				{ m: '房产所有人:', propName: modelData.value['houseOwner'] },
				{ m: '建筑面积:', propName: modelData.value['houseArea'] + '㎡' },
				{ m: '住宅情况:', propName: '', prop: 'slot1' },
			],
			[
				{ m: '居住人数:', propName: modelData.value['liveNum'] + '人' },
				{ m: '建成时间:', propName: modelData.value['buildTime'] + '年' },
				{ m: '户型:', propName: modelData.value['liveType'] },
			],
			[
				{
					m: '家庭联系人',
				},
				{
					m: '',
					prop: 'contacts',
				},
				{
					m: '联系电话',
				},
				{ m: '', prop: 'contactsPhone' },
			],
			[
				{ m: '人员类别', prop: '' },
				{
					m: '',
					align: 'left',
					prop: 'slot2',
					mc: {
						rs: 1,
						cs: 3,
					},
				},
			],
			[
				{ m: '改造需求', prop: '' },
				{
					m: '',
					prop: 'slot3',
					align: 'left',
					mc: {
						rs: 1,
						cs: 3,
					},
				},
			],
			[
				{ m: '申明', prop: '' },
				{
					m: '',
					align: 'left',
					prop: 'slot4',
					mc: {
						rs: 1,
						cs: 3,
					},
				},
			],
			[
				{
					m: '街道（镇）意见',
				},
				{
					m: '',
					align: 'left',
					prop: 'slot5',
					mc: {
						rs: 1,
						cs: 3,
					},
				},
			],
			[
				{
					m: '审批意见',
				},
				{
					m: '',
					align: 'left',
					prop: 'slot6',
					mc: {
						rs: 1,
						cs: 3,
					},
				},
			],
		]
		resovle(config)
	})
}
const dataList:any = ref([])
tableColumnConfig({}).then((config: any) => {
	dataList.value = config
})

const editMoneyAndYear = () => {
	let query = {
		id: props.editData.result_case_id,
		dataContent: modelData.value,
		dataResults: modelData.value,
		fromId: props.editData.formId,
		fromType: 'staff_entry_report',
		tableTemplateId: 'staff_entry_report',
		projectId: props.params.subsidyProjectId,
	}
	apiMod.view_formResults_edit(query).then((res) => {
		ElMessage.success('修改成功')
	})
}

const getInitData = async () => {
	modelData.value = props.editData
	if(props.editData['houseType']=='电梯房'){
		props.editData['houseTypeLabel'] = '0'
	}else if(props.editData['houseType']=='步梯房'){
		props.editData['houseTypeLabel'] = '1'
	}else if(props.editData['houseType']=='平房'){
		props.editData['houseTypeLabel'] = '2'
	}
	tableColumnConfig(modelData.value).then((config:any) => {
		dataList.value = config
	})
	console.log('看到', modelData.value)
}
onMounted(() => {
	if (props.params) getInitData()
})

const handleSave = () => {
	emit('save', modelData.value, 'elderly_change', props.editData)
}

onUnmounted(() => {})
</script>

<style scoped lang="scss">
.yi_jian {
	display: flex;
	flex-direction: row;
	justify-content: space-between;
	align-items: center;
	padding: 50px 5px 5px 5px;
	box-sizing: border-box;
}
.report-table-wrapper {
	width: 80%;
	margin: 0 auto;
	padding: 10px 30px;
	top: 0;

	.t-header {
		text-align: center;
		font-size: 18px;
		font-weight: bold;
		padding: 15px 0;

		.text-sm {
			font-weight: 400;
			font-size: 16px;
		}
	}
}

.article-title {
	position: relative;
	z-index: 0;
	width: 63%;
	margin: 0 auto;
}

.text-tip {
	--base-text-bg: rgb(56 176 255 / 13%);
	position: absolute;
	width: 100%;
	height: 100%;
	background: var(--base-text-bg);
	padding: 4px;
	z-index: -1;
	&:hover {
		cursor: pointer;
	}
	.tip-text-new {
		position: absolute;
		right: 0;
		top: -10px;
		color: #fff;
		border-radius: 4px;
		padding: 2px;
		width: 40px;
		background-color: #ed6d05;
	}
	.tip-text-detail {
		background-color: #179fe3;
		position: absolute;
		right: 0;
		top: -10px;
		color: #fff;
		border-radius: 4px;
		padding: 2px;
		width: 40px;
	}
}
</style>
